You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
17 lines
598 B
17 lines
598 B
import { getCache, setCache } from "#server/utils/context";
|
|
import { getCategoryById } from "../../service/category";
|
|
|
|
export default defineWrappedResponseHandler(async (event) => {
|
|
const id = getRouterParam(event, "id");
|
|
if (!id) return R.throwError(400, "Missing id", null);
|
|
|
|
const cacheKey = `category:${id}`;
|
|
const cached = await getCache(cacheKey);
|
|
if (cached) return R.success(cached);
|
|
|
|
const category = await getCategoryById(id);
|
|
if (!category) return R.throwError(404, "Category not found", null);
|
|
|
|
await setCache(cacheKey, category, 120);
|
|
return R.success(category);
|
|
});
|
|
|